{include_core file="lib/header.html" title="我的退款"}
<div class="content">
  <br><br>
  <div class="container clearfix">
    <!--start:我的退款-->
    <div class="refund">
      <div class="cart-title">我的退款</div>
      <div class="clearfix">
        <div class="refund-order left">
          <div class="title1">退款/退货商品</div>
          {$order_count = count($order_relation_list)}
          {if $order_count == 1}
            {foreach $all_list as $k=>$v}
              <div class="pic"><a href='{AnUrl("goods/`$v.goods_id`")}'><img src="{_image($v.image, 'middle')}"></a></div>
            {/foreach}
          {/if}
          {if $order_count > 1}
            <ul class="pic-list clearfix">
            {foreach $all_list as $k=>$v}
              <li class="js_goodsInfo" key-data="{$k}">
                <div class="pic"><a href='{AnUrl("goods/`$v.goods_id`")}'><img src="{_image($v.image, 'middle')}"></a></div>
                <h3 class="name"><a href='{AnUrl("goods/`$v.goods_id`")}'>{mb_substr($v.goods_title, 0, 12, 'utf-8')}</a></h3>
              </li>
            {/foreach}
          </ul>
          {/if}
          {foreach $all_list as $k=>$v}
          <div class="refund-order-detail {if $k > 0}hide{/if} js_goodsInfoDiv{$k} js_goodsInfoDiv">
            <dl class="clearfix">
              <dt>商品名称</dt>
              <dd>{$v.goods_title}</dd>
            </dl>
            <dl class="clearfix">
              <dt>商品数量</dt>
              <dd>{$v.goods_num}</dd>
            </dl>
            <dl class="clearfix">
              <dt>商品价格</dt>
              <dd>￥{$v.goods_price}</dd>
            </dl>
          </div>
          {/foreach}
          <div class="refund-order-detail">
            <dl class="clearfix">
                <dt>商品总价</dt>
                <dd>￥{$order_info.price}</dd>
              </dl>
            <dl class="clearfix">
              <dt>成交时间</dt>
              <dd>{substr($order_info.add_time,0,10)}</dd>
            </dl>
            <dl class="clearfix">
              <dt>订单号</dt>
              <dd>{order_helper::order_id_encode($order_info.id)}</dd>
            </dl>
            <dl class="clearfix">
              <dt>发票</dt>
              <dd>{if $order_info.invoice_title}{$order_info.invoice_title}{else}无发票{/if}</dd>
            </dl>
          </div>
        </div>
        <div class="refund-main right">
          <style>
            .refund_table{
              width:700px;
              margin-top: 10px;
            }
            .refund_table th{
              height:28px;
              background:#222;
            }
            .refund_table tr{
              border-bottom:1px solid #333;
            }
            .refund_table td{
              height:80px;
            }
            .refund_table tr:last-child td{
              height:60px;
            }
            .refund_table em{
              display:inline-block;
              margin-left:10px;
              margin-right:10px;
            }
           .refund_table tr div:hover{
              cursor:pointer;
           }
           .input_reason{
             margin-left:10px;
             background: none repeat scroll 0 0 #131313;
             border: 1px solid #2a2a2a;
             color: #95958c;
             font-size: 14px;
             height: 24px;
             line-height: 24px;
             padding: 3px 10px;
             width: 600px;
             height:50px;
             resize: none;
           }
          </style>
          <div>
            <div class="js_couponPrice" data-price="{if $coupon_price}{$coupon_price}{else}0{/if}" style="display:none;"></div>
            {if $coupon_price}
            <div style="font-size:14px;border:1px solid #333;padding:5px;background:#222; width:700px;">
                因为此订单在购买是使用了优惠券，所有在退款时会扣除优惠券抵消的价格：￥{$coupon_price}
            </div>
            {/if}
            {if !empty($order_relation_list)}
            <table class="refund_table">
              <tr>
                <th><h3 style="font-size:16px;">可退款商品</h3></th>
                <th colspan="2"><span style="font-size:14px;">&nbsp;--&nbsp;请选择退款商品</span></th>
                <th>数量</th>
                <th>单价</th>
                <th>可退款金额(小计)</th>
                <th>其他</th>
              </tr>
              {$refund_total_price = 0}
              {foreach $order_relation_list as $k=>$v}
              {$refund_total_price = $refund_total_price + $v.refund_price}
              <tr>
                <td><em class="cart-chked js_sltOrder" slt-data="1" id-data="{$v.id}"></em></td>
                <td>
                  <a href='{AnUrl("goods/`$v.goods_id`")}'>
                    <img src="{_image($v.image, 'small')}" width="60" height="60">
                  </a>
                </td>
                <td><a href='{AnUrl("goods/`$v.goods_id`")}'>{cut_str($v.goods_title, 20, '...')}</a></td>
                <td>{$v.goods_num}</td>
                <td>{$v.goods_price}</td>
                <td class="js_refundPrice">{$v.refund_price}</td>
                <td>{if $v.goods_price*$v.goods_num != $v.refund_price}抵消优惠券{/if}</td>
              </tr>
              {/foreach}
              <tr>
                <td><div class="js_sltAll" slt-data="1"><em class="cart-chked"></em>全选</div></td>
                <td colspan="2">
                    共计：￥<span class="js_totalPrice">{$refund_total_price}</span><br/>
                    {if $coupon_price}扣除优惠券：￥{$coupon_price}<br />{/if}
                    可退款：￥<span class="js_totalRefundPrice">{$refund_total_price - $coupon_price}</span>
                </td>
                <td colspan="4"></td>
              </tr>
            </table>
            {/if}
            {if !empty($refund_list)}
            <table class="refund_table">
              <tr>
                <th><h3 style="font-size:16px;">已退款商品</h3></th>
                <th colspan="2"></th>
                <th>数量</th>
                <th>单价</th>
                <th>已退款金额(小计)</th>
                <th>其他</th>
              </tr>
              {foreach $refund_list as $k=>$v}
              <tr>
                <td></td>
                <td>
                  <a href='{AnUrl("goods/`$v.goods_id`")}'>
                    <img src="{_image($v.image, 'small')}" width="60" height="60">
                  </a>
                </td>
                <td><a href='{AnUrl("goods/`$v.goods_id`")}'>{cut_str($v.goods_title, 20, '...')}</a></td>
                <td>{$v.goods_num}</td>
                <td>{$v.goods_price}</td>
                <td>{$v.refund_price}</td>
                <td>
                    {if $v.goods_price*$v.goods_num != $v.refund_price}抵消优惠券<br />{/if}
                    <a href='{AnUrl("order/refund_status?relation_id=`$v.id`")}'>退款详情</a>
                </td>
              </tr>
              {/foreach}
            </table>
            {/if}
            {if !empty($order_relation_list)}
            <div style="padding-top:20px;">
              退款理由:
              <textarea type="text" class="input_reason js_refundReason">仔细的填写退款理由能增加退款通过的几率</textarea></br></br></br>
              温馨提示:&nbsp;&nbsp;在退款前一定要联系我们的客服。
            </div>
          </div>
          <div class="refund-btns clearfix js_refundUp">
            <a style="height:60px;line-height:60px;" href='javascript:void(0);' type-data="1">我要{order_config::$refund_config['1']}</a>
            <a style="height:60px;line-height:60px;" href='javascript:void(0);' type-data="2">我要{order_config::$refund_config['2']}</a>
            {/if}
          </div>
        </div>
      </div>
    </div>
    <!--end:我的退款-->
  </div>
</div>
<script>
$(function(){
  $('.js_goodsInfo').mousemove(function(){
    var key = $(this).attr('key-data');
    $('.js_goodsInfoDiv').addClass('hide');
    $('.js_goodsInfoDiv'+key).removeClass('hide');
  });
  
  // 选择退款商品
  var refundIds = new Array();
  refundIds = getOrderIds();
  $('.js_sltAll').click(function(){
    var sltStatus = $(this).attr('slt-data');
    if (sltStatus == 1) {
      $(this).attr('slt-data', 0);
      $(this).children('em').removeClass('cart-chked');
      $(this).children('em').addClass('cart-chk');
      $('.js_sltOrder').attr('slt-data', 0);
      $('.js_sltOrder').removeClass('cart-chked');
      $('.js_sltOrder').addClass('cart-chk');
    } else {
      $(this).attr('slt-data', 1);
      $(this).children('em').addClass('cart-chked');
      $(this).children('em').removeClass('cart-chk');
      $('.js_sltOrder').attr('slt-data', 1);
      $('.js_sltOrder').addClass('cart-chked');
      $('.js_sltOrder').removeClass('cart-chk');
    }
    showTotalPrice();
  });
  $('.js_sltOrder').click(function(){
    var sltStatus = $(this).attr('slt-data');
    if (sltStatus == 1) {
      $(this).attr('slt-data', 0);
      $(this).removeClass('cart-chked');
      $(this).addClass('cart-chk');
    } else {
      $(this).attr('slt-data', 1);
      $(this).addClass('cart-chked');
      $(this).removeClass('cart-chk');
    }
    var orderNum = $('.js_sltOrder').length;
    var sltNum   = $('.js_sltOrder[slt-data=1]').length;
    if (sltNum == orderNum) {
      $('.js_sltAll').attr('slt-data', 1);
      $('.js_sltAll').children('em').addClass('cart-chked');
      $('.js_sltAll').children('em').removeClass('cart-chk');
    } else {
      $('.js_sltAll').attr('slt-data', 0);
      $('.js_sltAll').children('em').removeClass('cart-chked');
      $('.js_sltAll').children('em').addClass('cart-chk');
    }
    showTotalPrice();
  });

  // 提示信息
  $('.js_refundReason').focus(function(){
    if ($(this).val() == '仔细的填写退款理由能增加退款通过的几率') {
      $(this).val('');
    }
  });
  $('.js_refundReason').blur(function(){
    if ($(this).val() == '') {
      $(this).val('仔细的填写退款理由能增加退款通过的几率');
    }
  });
  
  // 提交退款
  $('.js_refundUp a').click(function(){
    var orderIds    = getOrderIds();
    var refundPrice = parseFloat($('.js_totalRefundPrice').html());
    var reason      = $('.js_refundReason').val();
    if (orderIds.length == 0) {
      showMsg('请选择需要退款的商品');
      return;
    }
    if (refundPrice <= 0) {
      showMsg('当前选择的商品还不能抵消优惠券的价格，不能退款');
      return;
    }
    if (reason == '仔细的填写退款理由能增加退款通过的几率') {
      reason = '';
    }
    
    orderStr = orderIds.join(',');
    var type = $(this).attr('type-data');
    $.post("{AnUrl('order/refund_save')}", { order_ids:orderStr, type:type, reason:reason }, function(data){
      if (data.info == 'ok') {
        $('.refund-main').html('<div class="refund-status">\
            <h3 class="title">请等待客服处理退款</h3>\
            <div class="txt">您的退款申请将在7日内处理，请耐心等待！</div></div>');
      } else {
        showMsg(data.info);
      }
    }, 'json');
  });
});
function getOrderIds()
{
  var ids = new Array();
  $('.js_sltOrder[slt-data=1]').each(function(){
    var id = $(this).attr('id-data');
    ids.push(id);
  });
  return ids;
}
function showTotalPrice()
{
  var couponPrice = parseFloat($('.js_couponPrice').attr('data-price'));
  var refundPrice = 0;
  $('.js_sltOrder[slt-data=1]').each(function(){
    var currPrice = parseFloat($(this).parent().nextAll().eq(4).html());
    refundPrice = refundPrice + currPrice;
  });
  $('.js_totalPrice').html(refundPrice);
  $('.js_totalRefundPrice').html(refundPrice - couponPrice);
}
</script>
{include_core file="lib/footer.html"}